package com.hyh.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.hyh.bean.UserInfoBean;
import com.hyh.myutils.MyUtils;
import com.hyh.service.impl.LoginServiceImpl;

/**
 * Servlet implementation class AdminInfoAddAction
 */
@WebServlet("/UsersInfoAddAction")
@MultipartConfig(maxFileSize=1024*1024*5) // 计算的基本单位是字节（byte）
public class UsersInfoAddAction extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 此处对用户注册的JSP页面进行业务处理,进行用户注册信息的匹配，若用户账号不存在，则添加，若存在，则返回用户已被注册！
		 
		
		// 进行查询操作
		UserInfoBean userB= MyUtils.convertFormData2Bean(request, UserInfoBean.class);
		// 2、调用service层进行数据保存
		int i = MyUtils.getInstance(LoginServiceImpl.class).saveOrUpdateUserInf(userB);
		
		// 3、根据保存处理结果进行页面转发
		if(i>0) {
		// 保存成功
			response.sendRedirect("addsucced.jsp");
		}else {
		// 保存失败
			response.sendRedirect("addfail.jsp");
				}
		
		
	}

}
